// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, but
// are changed infrequently
//

#ifndef _STDAFX_H_
#define _STDAFX_H_

#include <dlcom/cominc.h>
#include <dlcom/loadcom.hpp>
#include <comutiliy/base.h>


template<class T>
struct memless
{
	bool operator() (const T&left, const T&right) const
	{
		return memcmp(&left, &right, sizeof(T)) < 0;
	}
};

template<class _Ty>
class SortVector : public std::vector<_Ty>
{
public:
	typedef std::vector<_Ty> _base;
	void push_back(const _Ty& _Val)
	{
		if(_base::size() > 0)
		{
			push_back_sort(_Val);
		}
		else
		{
			_base::push_back(_Val);
		}
	}
	void push_back_sort(const _Ty& _Val)
	{
		typename _base::iterator _it = _base::begin();
		for(; _it != _base::end(); _it++)
		{
			if(_Val < *_it)
			{
				_base::insert(_it, _Val);
				return;
			}
		}

		if(_it == _base::end())
		{
			_base::push_back(_Val);
		}
	}
};

class Com_Plugin  
{
public:
	CLSID	ClsId;
	ULONG	uIndex;
	string	szComponent;
	~Com_Plugin()
	{
		uIndex		= 0;
		szComponent.clear();
	}

	Com_Plugin(
		CLSID id, 
		ULONG index, 
		const char* Component)
	{

		ClsId		= id;
		uIndex		= index;
		szComponent = Component;
	}

	bool operator>(const Com_Plugin &it) const
	{
		return uIndex > (it.uIndex);
	}

	bool operator <(const Com_Plugin &it) const
	{
		return !(operator >(it));
	}
};





typedef SortVector<Com_Plugin>						PluginVector;
typedef vector<basic_tstring>						ArgcVector;

typedef map<string,string>							ComponentPlugin;
typedef map<string,string>::iterator				ComponentPluginIterator;

class ClsInfo
{
public:
	string progid;
	string pname;
	ClsInfo()
	{
		progid.clear();
		pname.clear();
	}
	~ClsInfo()
	{
		progid.clear();
		pname.clear();
	}
};

typedef std::map<CLSID, ClsInfo, memless<CLSID> >	ClsIdTable;
typedef ClsIdTable::iterator						ClsIdTableiterator;
typedef ClsIdTable::const_iterator					ClsIdTableConstiterator;
typedef std::pair<ClsIdTableiterator, bool>			ClsIdTableBooliterator;

typedef std::map<string, CComLoader>				ContainerTable;
typedef ContainerTable::iterator					ContainerTableiterator;
typedef ContainerTable::const_iterator				ContainerTableConstiterator;
typedef std::pair<ContainerTableiterator, bool>		ContainerBooliterator;


std_com_export DllGetClassObject(REFCLSID rclsid, REFIID riid, void** ppv);

#endif

